<?php

class Request {

    private $controller;
    private $method;
    private $params;

    function __construct() {

        if (isset($_GET['url'])) {

            //filtro y descompongo la url en un array
            $url = filter_input(INPUT_GET, 'url', FILTER_SANITIZE_URL);
            $url = explode('/', $url);
            $url = array_filter($url);

            //extraigo controlador, metodo y parametros
            $this->controller = strtolower(array_shift($url));
            $this->method = strtolower(array_shift($url));
            $this->params = $url;
        }

        if (!$this->controller) {
            $this->controller = APP_DEFAULT_CONTROLLER;
        }
        if (!$this->method) {
            $this->method = 'main';
        }
    }

    public function getController() {
        return $this->controller;
    }

    public function getMethod() {
        return $this->method;
    }

    public function getParams() {
        return $this->params;
    }

}

?>
